package com.cskaoyan.wx.service;

import com.cskaoyan.bean.OrderExample;
import com.cskaoyan.mapper.OrderMapper;
import com.cskaoyan.mapper.UserMapper;
import com.cskaoyan.utils.UserUtils;
import com.cskaoyan.wx.vo.WxUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

@Service
public class WxUserServiceImpl implements WxUserService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    OrderMapper orderMapper;

    /**
     * 用户首页
     * @param
     * @return
     */
    @Override
    public WxUserVO getUserIndex() {
        Integer id = UserUtils.getUserId();

        WxUserVO.OrderBean orderBean = new WxUserVO.OrderBean();

        //待收货
        OrderExample orderExample = new OrderExample();
        OrderExample.Criteria criteria = orderExample.createCriteria();
        criteria.andDeletedNotEqualTo(true);
        criteria.andUserIdEqualTo(id);
        criteria.andOrderStatusEqualTo((short) 301);
        long count = orderMapper.countByExample(orderExample);
        orderBean.setUnrecv((int) count);

        //待评价
        OrderExample orderExample1 = new OrderExample();
        OrderExample.Criteria criteria1 = orderExample1.createCriteria();
        criteria1.andDeletedNotEqualTo(true);
        criteria1.andUserIdEqualTo(id);
        criteria1.andOrderStatusBetween((short) 401, (short) 402);
        long count1 = orderMapper.countByExample(orderExample1);
        orderBean.setUncomment((int) count1);

        //未支付
        OrderExample orderExample2 = new OrderExample();
        OrderExample.Criteria criteria2 = orderExample2.createCriteria();
        criteria2.andDeletedNotEqualTo(true);
        criteria2.andUserIdEqualTo(id);
        criteria2.andOrderStatusEqualTo((short) 101);
        long count2 = orderMapper.countByExample(orderExample2);
        orderBean.setUnpaid((int) count2);

        //未发货
        OrderExample orderExample3 = new OrderExample();
        OrderExample.Criteria criteria3 = orderExample3.createCriteria();
        criteria3.andDeletedNotEqualTo(true);
        criteria3.andUserIdEqualTo(id);
        criteria3.andOrderStatusEqualTo((short) 201);
        long count3 = orderMapper.countByExample(orderExample3);
        orderBean.setUnship((int) count3);

        WxUserVO wxUserVO = new WxUserVO();
        wxUserVO.setOrder(orderBean);
        return wxUserVO;
    }
}
